#include "dlg_bookau.h"
#include "ui_dlg_bookau.h"

Dlg_BookAU::Dlg_BookAU(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dlg_BookAU)
{
    ui->setupUi(this);
}

Dlg_BookAU::~Dlg_BookAU()
{
    delete ui;
}

void Dlg_BookAU::setType(int id)
{
    m_Id= id;

    //执行sql语句并将查询结果显示到控价上

    auto l = Sql_Mgr::getInstance()->getBook("", id);
    if(1 == l.size())
    {
        ui->le_name->setText(l[0][1]);
        ui->le_press->setText(l[0][2]);
        ui->cb1->setCurrentText(l[0][3]);
        ui->cb2->setCurrentText(l[0][4]);
        ui->cb3->setCurrentText(l[0][5]);
        ui->le_cnt->setText(l[0][6]);
    }



}

void Dlg_BookAU::on_btn_cel_clicked()
{
    this->hide();
}


void Dlg_BookAU::on_btn_ok_clicked()
{
    QStringList l;
    l<<QString::number(m_Id);
    l<<ui->le_name->text();
    l<<ui->le_press->text();
    l<<ui->cb1->currentText();
    l<<ui->cb2->currentText();
    l<<ui->cb3->currentText();
    l<<ui->le_cnt->text();
    l<<"";

    if(-1 !=m_Id)
    {
        //update
        Sql_Mgr::getInstance()->updateBook(l);
    }
    else
    {
        //add
        QVector<QStringList> vec;
        vec.push_back(l);
        Sql_Mgr::getInstance()->addBooks(vec);
    }
    this->hide();
}

